package com.itheima.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.mall.mapper.CouponHistoryMapper;
import com.itheima.mall.pojo.CouponHistory;
import com.itheima.mall.service.SmsCouponHistoryService;
import com.itheima.mall.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class SmsCouponHistoryServiceImpl implements SmsCouponHistoryService {

    @Autowired
    private CouponHistoryMapper couponHistoryMapper;

    /**
     * 根据优惠券id，使用状态，订单编号分页获取领取记录
     */
    @Override
    public PageResult list(Integer couponId, String orderSn, Integer pageNum, Integer pageSize, Integer useStatus) {
        Page<CouponHistory> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<CouponHistory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(orderSn != null,CouponHistory::getOrderSn,orderSn)
                .eq(couponId != null,CouponHistory::getCouponId,couponId)
                .eq(useStatus != null,CouponHistory::getUseStatus,useStatus);
        Page<CouponHistory> pageInfo = couponHistoryMapper.selectPage(page, queryWrapper);

        return new PageResult(pageNum,pageSize, (int) pageInfo.getTotal(),pageInfo.getRecords());
    }

}
